package com.siriframe.mongodb.controller;


import com.siriframe.core.entity.Page;
import com.siriframe.entity.Result;
import com.siriframe.mongodb.entity.User;
import com.siriframe.mongodb.entity.resp.UserInfoResp;
import com.siriframe.mongodb.entity.vo.UserPageReq;
import com.siriframe.mongodb.entity.vo.UserSaveReq;
import com.siriframe.mongodb.entity.vo.UserUpdateReq;
import com.siriframe.mongodb.handler.UserHandler;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 测试数据 接口
 */
@RestController
@RequestMapping("user")
@Api("测试数据 接口")
public class UserController {

    @Autowired
    private UserHandler userHandler;

    @PostMapping("/save")
    public Result<Boolean> save(@RequestBody UserSaveReq req) {
        return userHandler.save(req);
    }

    @PostMapping("/update")
    public Result<Boolean> update(@RequestBody UserUpdateReq req) {
        return userHandler.update(req);
    }

    @DeleteMapping("/delete/{id}")
    public Result<Boolean> deleteById(@ApiParam(value = "id") @PathVariable String id) {
        return userHandler.deleteById(id);
    }

    @GetMapping("/get/{id}")
    public Result<UserInfoResp> getById(@ApiParam(value = "id") @PathVariable String id) {
        return userHandler.getById(id);
    }

    @ApiOperation(value = "05-分页查询测试数据")
    @PostMapping("/page")
    public Result<Page<User>> queryList(@RequestBody UserPageReq req) {
        return userHandler.queryList(req);
    }

}
